package com.prj.ufdm.cloud.ms;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;

import com.prj.ufdm.cloud.ms.order.enums.ServiceNameConsts;


@SpringBootApplication
@RibbonClients(value = {
        @RibbonClient(name = ServiceNameConsts.SERVICE_MS_TEST),
        @RibbonClient(name = ServiceNameConsts.SERVICE_MS_WAREHOUSE)
})
public class UfdmOrderApplication extends SpringBootServletInitializer implements EnvironmentAware  {

	private static Environment env; 
	
	public static void main(String[] args) {
		SpringApplication.run(UfdmOrderApplication.class, args); 
		System.out.println("\n ms-warehouse "+ env.getProperty("server.port") +" 启动成功................"); 
	}

	@Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(UfdmOrderApplication.class);
    }
	
	@Override
	public void setEnvironment(Environment environment) {
		env = environment;
	}
	
	@Bean
	@LoadBalanced
	public RestTemplate getRestTemplate() {
		return new RestTemplate();
	}

}
